package com.flying.invest.summary.model;

import com.flying.common.util.StringUtils;

interface ISummary {
	String getString(String key);
	
	Double getCurrencyRate();
	
	Double getTotalAmount(); 
	
	void setTotalAmount(Double totalAmount);
	
	Double getTotalCost() ;
	
	void setTotalCost(Double totalCost);
	
	Double getTotalProfit();
	
	void setTotalProfit(Double totalProfit);
	
	Double getTotalTax() ;
	
	void setTotalTax(Double totalTax);
	
	default void reCalculate() {
		this.setTotalAmount(this.getTotalAmount() * this.getCurrencyRate());
		this.setTotalCost(this.getTotalCost() * this.getCurrencyRate());
		this.setTotalTax(this.getTotalTax() * this.getCurrencyRate());
		this.setTotalProfit(this.getTotalProfit() * this.getCurrencyRate());
	}
	
	default <T extends ISummary> void mergeMoney(T s) {
		s.reCalculate();
		this.setTotalAmount(this.getTotalAmount() + s.getTotalAmount());
		this.setTotalCost(this.getTotalCost() + s.getTotalCost());
		this.setTotalTax(this.getTotalTax() + s.getTotalTax());
		this.setTotalProfit(this.getTotalProfit() + s.getTotalProfit());
	}
	
	default <T extends ISummary> boolean match(T s, String[] keys) {
		for(String k: keys) {
			String v1 = this.getString(k);
			String v2 = s.getString(k);
			if(!StringUtils.equals(v1, v2)) {
				return false;
			}
		}
		return true;
	}
}
